package DRCOMM;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import com.fasterxml.jackson.databind.ObjectMapper;

public class dr_menu{


    public String code="";
    public boolean enable=true;
    public String href="";
    public String icon="icon-photovoltaic";
    public int id=1;
    public String parentId="None";
    public String title="";
    public List<dr_menu> children=new ArrayList<dr_menu>();

    public dr_menu(String code,String href,int id,String title){
        this.code=code;
        this.href=href;
        this.id=id;
        this.title=title;
    }

    public void disable_menu(){
        this.enable=false;
    }

    public void add_children(dr_menu dm){
        this.children.add(dm);
    }
    
    public String get_answer_json_str(int code,String msg){
        List<dr_menu> dm_list=new ArrayList<dr_menu>();
        dm_list.add(this);
        dr_ajax_answer daa=new dr_ajax_answer(code, msg);
        daa.set_data(dm_list);
        return daa.json_string();
    }

    /**
     * 根据菜单列表返回菜单json
     * @param code
     * @param msg
     * @param dm
     * @return
     */
    public static String get_answer_json_str(int code,String msg,List<dr_menu> dm){
        dr_ajax_answer daa=new dr_ajax_answer(code, msg);
        daa.set_data(dm);
        return daa.json_string();
    }

    public static void main(String[] args){
        dr_menu dm=new dr_menu("c1", "", 1, "主菜单");
        dr_menu dm1=new dr_menu("c11", "channel/channel-list.html", 11, "通道管理");
        dm.add_children(dm1);
        ObjectMapper mapper = new ObjectMapper();
        try {
            System.out.println(mapper.writeValueAsString(dm));
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}